package com.apping.module.button;

import com.apping.module.R;
import com.umeng.analytics.MobclickAgent;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MajorBtnAtv extends Activity {

	private SelectEvent m_selectEvent;
	private Class<?> m_cls;
	private Intent m_intent;

	public void initUI() {
		Button customBgBtnV = (Button) findViewById(R.id.minor_custom_bg_button);
		customBgBtnV.setOnClickListener(m_selectEvent);

		Button systemButton = (Button) findViewById(R.id.minor_system_button);
		systemButton.setOnClickListener(m_selectEvent);

		Button buttonClick = (Button) findViewById(R.id.minor_button_click);
		buttonClick.setOnClickListener(m_selectEvent);
	}

	public void NextAtv() {
		m_intent.setClass(getApplication(), m_cls);
		startActivity(m_intent);
		this.finish();
	}

	public void SetNextAtv(Class<?> cls) {
		m_cls = cls;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.apping_button);
		m_selectEvent = new SelectEvent(this);
		m_intent = new Intent();
		initUI();

	}

	public void onResume() {
		super.onResume();
		MobclickAgent.onPageStart("SplashScreen"); // 统计页面
		MobclickAgent.onResume(this); // 统计时长
	}

	public void onPause() {
		super.onPause();
		MobclickAgent.onPageEnd("SplashScreen"); // 保证 onPageEnd 在onPause
													// 之前调用,因为 onPause 中会保存信息
		MobclickAgent.onPause(this);
	}
}

class SelectEvent implements OnClickListener {
	private MajorBtnAtv m_atv;

	public SelectEvent(MajorBtnAtv atv) {
		m_atv = atv;
	}

	@Override
	public void onClick(View v) {
		int id;
		id = v.getId();
		if (id == R.id.minor_custom_bg_button) {
			m_atv.SetNextAtv(CustomBgBtnAtv.class);
		}

		if (id == R.id.minor_system_button) {
			m_atv.SetNextAtv(SystemButtonAtv.class);
		}

		if (id == R.id.minor_button_click) {
			m_atv.SetNextAtv(ButtonClickEventAtv.class);
		}

		m_atv.NextAtv();
	}

}
